Skip to content

perf(agc): bind the address space's BDA table for writes inside writable imports - #4979

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
AlxcBTW:perf/bda-writable-writes-space-table
Oct 14, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
AlxcBTW:perf/bda-writable-writes-space-table

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

What

GuestBufferMemory::CachedAddressTable() returns the cached address space's own BDA table (its serial and ranges) for a build whose writes all land in ranges that already have write permission, instead of building and keying a table per set of written addresses.

AddressRanges() splits only the space's ranges without write permission around the written intervals. When no written interval overlaps such a range, its result is the space's own ranges, so the build binds the space's table by the space serial, as a build without writes does. The check is a bisection per written interval over the space's sorted, disjoint ranges. A write that overlaps a range without write permission (a writable image mirror inside a read-only import) keeps the per-writes table as before.

No environment switch: the path is always on and exact.

Why

A build that maps only the cached space but writes through V#s got a table keyed by its writes: a new key for nearly every set of written addresses, so each such build merged the space's imported ranges (about 9000 in Sword of the Sea gameplay), stored them, then hashed and compared them in BdaResources. In a CPU sample of the lab line (Sword of the Sea gameplay, RTX 5070) CachedAddressTable and hashRanges were about 4 % of the q0 thread.

This is independent of the read-list change and has no dependency on it. I did not measure it in isolation on main; the figure above is a sampling share on the lab line, not a measured FPS gain.

Tested

  • tests/BdaResources.cpp spaceWritableWritesTests (in agc_driver_graphics), with a writable and a read-only import registered: builds with one write and with two writes inside the writable import bind the serial of the build without writes, and the cached ranges equal AddressRanges() (the full walk) and the ranges of the build without writes; the read-only import stays without write permission. On main the serial differs per set of writes, so the test fails there.
  • tools/check_conventions.py --base origin/main: passed.
  • CI on the fork (Linux and Windows, same steps as build.yml): Linux and Windows green, 0 failures (https://github.com/AlxcBTW/AnyPS5/actions/runs/38357743201), run before a rebase onto a main that only added tests/ShaderMemory.cpp
  • No game was started for this PR.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

@xXPBSXx

xXPBSXx commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on main 2a2a3dc65 together with nine other open GPU PRs (their own commits applied, no merge commits; one further PR, #5024, conflicted with them and was left out), so only the tests that belong to this PR say something about it:

Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed.

AI-assisted (Claude Code).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
…ble imports

A build mapping only the cached address space but writing through V#s got a
table keyed by its writes: a new key for nearly every set of written
addresses, so each such build merged the space's imported ranges, stored them,
then hashed and compared them in BdaResources.

AddressRanges splits only ranges without write permission around the written
intervals. When no written interval overlaps such a range of the space, its
result is the space's own ranges, so the build binds the space's table by the
space serial, as a build without writes does. A write overlapping a range
without write permission keeps the per-writes table.

Test: builds with one and two writes inside a writable import bind the serial
and the ranges of the build without writes, equal to AddressRanges(), and keep
the read-only import without write permission.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlxcBTW
AlxcBTW force-pushed the perf/bda-writable-writes-space-table branch from e4ac947 to d95634b Compare October 13, 2026 18:24
@AlxcBTW

AlxcBTW commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main. The only conflict was the test call list in tests/BdaResources.cpp. Full ctest on the fork CI is green on Windows and Linux, apart from the host-libm guest_math case (#5154).

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5542 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L3798-3799

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the new path against AddressRanges(): with no written interval overlapping a range without write permission, the split leaves the space's ranges unchanged, so binding the space's table and serial is equivalent. Built and ran the libSceAgcDriver tests on the PR merged onto main: agc_driver_graphics (with spaceWritableWritesTests) passes and fails with GuestBufferMemory.cpp reverted. Also thanks to @xXPBSXx for the Windows run. Merging once the full Build is green.

@adriadam10
adriadam10 merged commit 905f197 into boykopovar:main Oct 14, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants